﻿using System.Drawing;
using System.Windows.Forms;
namespace RPG1
{
    public class Role
    {
        private string name;
        private int originalLife; // 原始生命值
        private int currentLife; // 当前生命值
        private int damage;  // 力量
        private Point currentLocation; // 原始位置
        private Point originaLocation ;//  当前位置
        private PictureBox picBox;
        private Label bottomLabel;
        private Label topLabel;

        public Role(string name, int originalLife, int currentLife, int damage,
            PictureBox picBox, Label bottomLabel, Label topLabel)
        {
            Name = name;
            OriginalLife = originalLife;
            CurrentLife = currentLife;
            Damage = damage;
            PicBox = picBox;
            BottomLabel = bottomLabel;
            TopLabel = topLabel;

            CurrentLocation = PicBox.Location;
            OriginaLocation = PicBox.Location;
        }
        public void Delay()
        {
            for (int i = 0; i < 20000; i++)
                Application.DoEvents();
        }
        public string Name { get => name; set => name = value; }
        public int OriginalLife { get => originalLife; set => originalLife = value; }
        public int CurrentLife { get => currentLife; set => currentLife = value; }
        public int Damage { get => damage; set => damage = value; }
        public Point CurrentLocation { get => currentLocation; set => currentLocation = value; }
        public Point OriginaLocation { get => originaLocation; set => originaLocation = value; }
        public PictureBox PicBox { get => picBox; set => picBox = value; }
        public Label BottomLabel { get => bottomLabel; set => bottomLabel = value; }
        public Label TopLabel { get => topLabel; set => topLabel = value; }

        public void move()
        {
            //返回，当前位置=原始位置
            int diffX = OriginaLocation.X - PicBox.Location.X;
            int diffY = OriginaLocation.Y - PicBox.Location.Y;
            for(int i = 1; i <= 10; i++) {
                PicBox.Location = new Point(PicBox.Location.X + diffX/ 10,
                    PicBox.Location.Y + diffY / 10);
                TopLabel.Location = PicBox.Location;
                BottomLabel.Location = PicBox.Location;
                Delay();
            }
        }
        public void bloodLoss(int enemyDamage)
        {
            CurrentLife -= enemyDamage;
           
            if (CurrentLife <= 0)
                CurrentLife = 0;
            TopLabel.Width = (int)(1.0*CurrentLife / OriginalLife * BottomLabel.Width);
            //MessageBox.Show(""+1.0*CurrentLife / OriginalLife);
            TopLabel.Text = " " + (1.0 * CurrentLife / OriginalLife * 100)+"%";
            BottomLabel.BringToFront();
            TopLabel.BringToFront();
        }
    }
}
